<template>
    <div style="display: flex;line-height: 60px; text-align: center">
        <div style="margin-top: 8px;">
            <i :class="aside_icon" style="font-size: 20px;cursor: pointer;" @click="collapse"></i>
        </div>
        <div style="flex: 1;text-align: center;font-size: 34px; color: white;">
            <span>learn and live</span>
        </div>
        <el-dropdown>
            <i class="el-icon-caret-bottom" style="margin-right: 15px"></i>
            <el-dropdown-menu slot="dropdown" style="margin-top: -20px;">
                <el-dropdown-item @click.native="toUser" icon="el-icon-user">| 个人中心</el-dropdown-item>
                <hr style="solid-color: #c0ccda"></hr>
                <el-dropdown-item @click.native="logout" icon="el-icon-switch-button">| 退出登录</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
        <span><U>{{user.name}}</U></span>
    </div>
</template>

<script>
    export default {
        name: "Header",
        data(){
            return {
                 user: JSON.parse(sessionStorage.getItem("CurUser"))
            }
        },
        props:{
            aside_icon:String
        },
        methods: {
            toUser(){
                this.$router.replace("/Home")
            },
            logout(){
                console.log('注销ing');

                this.$confirm('确定退出登录吗?','提示',{
                    confirmButtonText: '确定', //确认按钮显示的文字
                    type:'warning',
                    center: true, //文字居中显示
                    showCancelButton: true, //是否显示 取消按钮
                    showClose: true, //是否显示右上角的 X
                    closeOnClickModal: true, //是否可以点击空白处关闭窗口

                }).then(()=>{

                    this.$message.success('退出登录成功');

                    this.$router.push("/login");
                    sessionStorage.clear();
                })
                    .catch(()=>{
                        this.$message.info('退出登录已取消')
                    })


            },
            collapse(){
                this.$emit('doCollapse')
            }
        }

    }
</script>

<style scoped>

</style>